package seelction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by mHandler on 2018/5/6 0006.
 * Description:
 */
public class Student implements Comparable<Student> {

    private String name;
    private int score;

    public Student(String name, int score){
        this.name = name;
        this.score = score;
    }

    @Override
    public int compareTo(Student o) {
        if (this.score == o.score)
            return this.name.compareTo(o.name);
        if (this.score > o.score)
            return 1;
        else if (this.score < o.score)
            return -1;
        else
        return 0;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();

        Student s1= new Student("a",11);
        Student s2= new Student("d",15);
        Student s3= new Student("c",13);
        Student s4= new Student("b",12);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        Collections.sort(list);
//        for (Student student : list){
//            System.out.println(student);
//        }
        //二分查找，前提是该列表有序
        System.out.println(Collections.binarySearch(list,s3));


    }
}
